
#include "WorkerThread.h"

WorkerThread::WorkerThread(std::function<void()> &&fun) : call_back(fun) {}

WorkerThread::~WorkerThread() {}

void WorkerThread::Run() {
    while (!stoped) {
        std::unique_lock<std::mutex> pauseLock(pause_mutex);
        pause_cv.wait(pauseLock, [this]() { return !paused; });
        if (call_back) {
            call_back();
        }
    }
}

void WorkerThread::Pause() {
    std::lock_guard<std::mutex> lock(pause_mutex);
    paused = true;
    pause_cv.notify_all();
}

void WorkerThread::Resume() {
    std::lock_guard<std::mutex> lock(pause_mutex);
    paused = false;
    pause_cv.notify_all();
}

void WorkerThread::Stop() {
    std::lock_guard<std::mutex> lock(pause_mutex);
    stoped = true;
}
